#include "precompile.h"

#include "CreateImageItemCommand.h"

#include "command/arg/ImageItemArgument.h"
#include "document/DocumentID.h"
#include "document/IImageItem.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CreateImageItemCommand::CreateImageItemCommand()
{
}

CreateImageItemCommand::~CreateImageItemCommand()
{
}

void CreateImageItemCommand::Execute()
{
	ImageItemArgument* sarg = dynamic_cast<ImageItemArgument*>(arg);

	sys::ServiceInterfacePtr<IHierarchyService> pIFHierarchyService(HIERARCHY_SERVICE);
	IObject* spread = pIFHierarchyService->GetSpread(ctx->GetRoot(),ctx->GetactiveTarget());
	sys::ServiceInterfacePtr<IBuildService> pIFBuildService(BUILD_SERVICE);

	IObject* item = pIFBuildService->BuildRegion(spread,sarg->category,CLSID_ImageItem,sarg->points);
	sys::InterfacePtr<IImageItem> pIFImageItem(item);
	pIFImageItem->setPath(sarg->imagePath);
	if (item)
		ctx->Select(item);
}